package cn.itcast.bos.service.impl;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.itcast.bos.dao.StandardRepository;
import cn.itcast.bos.domain.base.Standard;
import cn.itcast.bos.service.StandardService;

@Service
@Transactional
public class StandardServiceImpl implements StandardService {

	// 注入Dao
	@Autowired
	StandardRepository standardRepository;
	
	@Override
	public void save(Standard standard) {
		standardRepository.save(standard);// 如果实体中的ID不存在，执行save；如果是实体中的ID存在，执行update。
	}
	
	@Override
	public List<Standard> findByName(String name) {
		return standardRepository.findByName(name);
	}
	
	// 分页查询
	@Override
	public Page<Standard> findPageQuery(Pageable pageable) {
		return standardRepository.findAll(pageable);
	}
	
	
	// 删除
	@Override
	public void deleteByIds(String ids) {
		if(StringUtils.isNotBlank(ids)){
			String[] array = ids.split(",");
			if(array!=null && array.length>0){
				for(String id:array){
					standardRepository.delete(Integer.parseInt(id));
				}
			}
		}
	}
	
	@Override
	public List<Standard> findAll() {
		return standardRepository.findAll();
	}
}
